<%-- 
    Document   : list_order
    Created on : Jan 21, 2013, 2:09:20 PM
    Author     : SONY
--%>

<%@page import="java.text.SimpleDateFormat"%>
<%@page import="model.Product"%>
<%@page import="model.ProductService"%>
<%@page import="model.SaleOrderDetail"%>
<%@page import="model.SaleOrderDetailService"%>
<%@page import="java.sql.Timestamp"%>
<%@page import="model.SaleOrder"%>
<%@page import="java.util.ArrayList"%>
<%@page import="model.User"%>
<%@page import="model.SaleOrderService"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<table id="cart" border=1 cellspacing=0 cellpadding=4 bordercolor=lightgray width="100%">
    <tr bgcolor=#dadddd>
            <th>Mã Đơn Hàng</th>
            <th>Ngày Đặt Hàng</th>
            <th>Tổng Tiền (đ)</th>
            <th>Trạng Thái</th>
    </tr>
<% 
    User user = (User) session.getAttribute("user_member");
    int MemberID = user.getMemberID();
    SaleOrderService sale_order_service = new SaleOrderService();
    ArrayList<SaleOrder> lstSaleOrder = sale_order_service.getSaleOrders_byMemberID(MemberID);
    int j = 0;
    for(int i = 0; i < lstSaleOrder.size(); i++) {
        String color = ++j % 2 == 0 ? "#f9e7dd" : "#eec7b7";
        int SaleOrderID = lstSaleOrder.get(i).getSaleOrderID();
        Timestamp OrderDate = lstSaleOrder.get(i).getOrderDate();
        String date_str = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(OrderDate);
        double TotalPrice = lstSaleOrder.get(i).getTotalPrice();
        String Status = lstSaleOrder.get(i).getStatus();
%>
    <tr bgcolor="<%=color%>">
        <td align=center><%=SaleOrderID%></td>
        <td align=center><%=date_str%></td>
        <td align=right><fmt:formatNumber type="currency" currencySymbol="" maxFractionDigits="0" value="<%=TotalPrice%>"/></td>
        <td align=center><%=Status%></td>
    </tr>
    <tr bgcolor=#dadddd>
        <td colspan="4">
            <table id="cart" border=1 cellspacing=0 cellpadding=4 bordercolor=lightgray width="650px" style="margin-left: 15px; margin-bottom: 15px;">
                <tr bgcolor=#b7b8b8>
                    <th>#</th>
                    <th>Mã Sản Phẩm</th>
                    <th>Tên Sản Phẩm</th>
                    <th align=center>Đơn Giá (đ)</th>
                    <th>Số Lượng</th>
                    <th>Thành Tiền (đ)</th>
                </tr>
<% 
    SaleOrderDetailService sale_order_detail_service = new SaleOrderDetailService();
    ArrayList<SaleOrderDetail> lstSaleOrderDetails = sale_order_detail_service.getSaleOrderDetails_bySaleOrderID(SaleOrderID);
    int k = 0;
    for(int m = 0; m < lstSaleOrderDetails.size(); m++) {
        String color_table2 = ++k % 2 == 0 ? "#f8ad9a" : "#f4c3b6";      
        String pid = lstSaleOrderDetails.get(m).getProductID();
        int qty = lstSaleOrderDetails.get(m).getOrderQuantity();
        double totallinefmt = lstSaleOrderDetails.get(m).getLineTotal();
        ProductService product_service = new ProductService();
        Product product = product_service.getProductDetails_byPID(pid);
        String pname = product.getProductName();
        double unitpricefmt = product.getUnitPrice();       
%>
                <tr bgcolor="<%=color_table2%>">
                        <td align=center><%=k%></td>
                        <td align=center><a href="../nonmember/product_details.jsp?<%=pid%>"><%=pid%></a></td>		
                        <td align=center><%=pname%></td>
                        <td align=right><fmt:formatNumber type="currency" currencySymbol="" maxFractionDigits="0" value="<%=unitpricefmt%>"/></td>
                        <td align=center><%=qty%></td>
                        <td align=right><fmt:formatNumber type="currency" currencySymbol="" maxFractionDigits="0" value="<%=totallinefmt%>"/></td>
                </tr>

<% } %>
            </table>
        </td>
    </tr>
<% } %>
</table>
